﻿
using Leeder.Logger;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScanConfirm.PdaServer
{
    public class TcpService
    {
        private LogOperate LogObj => Log.GetLogger(this.GetType());
        private string nowVin { get; set; }
        /// <summary>
        /// 获取VIN码
        /// </summary>
        /// <param name="pararm"></param>
        /// <returns></returns>
        public string getVinData(string pararm)
        {

            PdaVinData pvd = new PdaVinData();

            try
            {
                var stringResulr = JsonConvert.DeserializeObject<PdaVinData>(pararm);
                int stg = stringResulr.FunId;

            }
            catch (Exception ex)
            {
                LogObj.Error("PdaVinData对象解析出错!!" + "---" + ex.Message);
                pvd.IsData = false;
            }


            return JsonConvert.SerializeObject(pvd);

        }

        /// <summary>
        /// 获取Mark
        /// </summary>
        /// <param name="pararm"></param>
        /// <returns></returns>
        public string getMark(string pararm)
        {

            PdaVinData pvd = new PdaVinData();

            try
            {
                pvd = JsonConvert.DeserializeObject<PdaVinData>(pararm);
                int stg = pvd.FunId;

            }
            catch (Exception ex)
            {
                LogObj.Error("PdaVinData对象解析出错!!" + "---" + ex.Message);
                pvd.IsData = false;
            }


            return pvd.Mark;

        }

        /// <summary>
        /// 处理扫描结果 返回类型位元数据
        /// </summary>
        /// <param name="psd"></param>
        /// <returns></returns>
        public Tuple<string, PdaSendResult, PdaSendData> getSendMessageResult(string psd)
        {
            PdaSendResult pdaSendResult = new PdaSendResult();
            PdaSendData stringResulr = new PdaSendData();
            try
            {
                stringResulr = JsonConvert.DeserializeObject<PdaSendData>(psd);
                var vinString = stringResulr.vin;
                var componetCode = stringResulr.ScanInfo;

                pdaSendResult.Code = 0;
                pdaSendResult.Message = "正常";


            }
            catch (Exception ex)
            {
                LogObj.Error("接收处理扫描结果异常!!!:" + psd + "---"+ ex.Message);
            }
            var returnString = JsonConvert.SerializeObject(pdaSendResult);

            return new Tuple<string, PdaSendResult, PdaSendData>(returnString, pdaSendResult, stringResulr);
        }


        public Tuple<string, int> LoginHandler(string psd, string ip)
        {
            var ipRemote = ip.Split(':')[0];
            PdaSendResult pdaSendResult = new PdaSendResult();
            int loginRes = 99;
            try
            {
                if (1==1)
                {
                    pdaSendResult.Code = 0;
                    loginRes = 1;

                }
                else
                {
                    pdaSendResult.Code = 2;
                }
            }
            catch (Exception ex)
            {
                pdaSendResult.Code = 2;
                LogObj.Error(ex);
            }
            var returnString = JsonConvert.SerializeObject(pdaSendResult);

            return new Tuple<string, int>(returnString, loginRes);
        }

    }
}
